//
//  MainScreenView.m
//  Checkers2015
//
//  Created by Dmitry Tatarinov on 2/13/15.
//  Copyright (c) 2015 Huly-Gun Soft. All rights reserved.
//

#import "MainScreenView.h"

@implementation MainScreenView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect) frame andDelegate: (id) vcDelegate
{
    if (self = [super initWithFrame:frame])
    {
        [self setupInterfaceItems];
        delegate = vcDelegate;
    }
    
    return self;
}

- (void)setupInterfaceItems
{
    CGFloat ofset = 32;
    CGFloat btnWidth = 128.0;
    CGFloat btnHeight = 48.0;
    
     UIButton *_onePlayerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
     [_onePlayerBtn setTitle:@"1 Player" forState:UIControlStateNormal];
     [_onePlayerBtn setFrame:CGRectMake(0, 0, btnWidth, btnHeight)];
     _onePlayerBtn.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 - ofset);
     _onePlayerBtn.tag = 100;
     [_onePlayerBtn addTarget:self action:@selector(mainViewBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
     [self addSubview:_onePlayerBtn];
     
     UIButton *_twoPlayersBtn = [UIButton buttonWithType:UIButtonTypeCustom];
     [_twoPlayersBtn setTitle:@"2 Players" forState:UIControlStateNormal];
     [_twoPlayersBtn setFrame:CGRectMake(0, 0, btnWidth, btnHeight)];
     _twoPlayersBtn.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 + ofset);
     _twoPlayersBtn.tag = 200;
     [_twoPlayersBtn addTarget:self action:@selector(mainViewBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
     [self addSubview:_twoPlayersBtn];
    
    ofset = 8.0;
    btnWidth = 48.0;
    
    UIButton *_gameCenterBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_gameCenterBtn setTitle:@"GC" forState:UIControlStateNormal];
    [_gameCenterBtn setFrame:CGRectMake(0, 0, btnWidth, btnHeight)];
    _gameCenterBtn.center = CGPointMake(ofset + btnWidth/2, SCREEN_HEIGHT - ofset - btnHeight/2);
    _gameCenterBtn.tag = 700;
    [_gameCenterBtn addTarget:self action:@selector(mainViewBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_gameCenterBtn];
    
    UIButton *_inappBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_inappBtn setTitle:@"Ads" forState:UIControlStateNormal];
    [_inappBtn setFrame:CGRectMake(0, 0, btnWidth, btnHeight)];
    _inappBtn.center = CGPointMake(SCREEN_WIDTH - ofset - btnWidth/2, SCREEN_HEIGHT - ofset - btnHeight/2);
    _inappBtn.tag = 800;
    [_inappBtn addTarget:self action:@selector(mainViewBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_inappBtn];

}

- (void)mainViewBtnPressed: (id) sender
{
    NSLog(@"pressed: %li", (long)[sender tag]);
    [delegate mainScreenBtnPressed:sender];
    
    if ([sender tag] < 300){
        [self removeFromSuperview];
    }
}

@end
